{{ define "title" }}{{ i18n "archive" }} - {{ .Site.Title }}{{ end }}

{{ define "content"}}
{{- $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Type" "post") (index .Site.Params "archive-paginate" | default 10) }}
<section id="archive" class="archive">
  {{- if not $paginator.HasPrev }}
    <div class="archive-title">
      <span class="archive-post-counter">
        {{- $length := len .Data.Pages }}
          {{ i18n "counter_archives" $length }}
      </span>
    </div>
  {{- end -}}

  {{- range $index, $element := $paginator.Pages -}}
    {{- $thisYear := $element.Date.Format "2006" }}
    {{- $lastElement := $index | add -1 | index $paginator.Pages }}
    {{ if or (eq $index 0) ( ne ($lastElement.Date.Format "2006") $thisYear ) }}
      <div class="collection-title">
        <h2 class="archive-year">{{ $thisYear }}</h2>
      </div>
    {{- end }}

    <div class="archive-post">
      <time datetime="{{ .Date.Format "2006-01-02" }}" class="archive-post-time">
        {{ .Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }}
      </time>
      <span class="archive-post-title">
        <a href="{{ $element.RelPermalink }}" class="archive-post-link">
          {{ .Title }}
        </a>
      </span>
    </div>
  {{- end -}}
</section>

<!-- pagination -->
{{ partial "pagination.html" . }}

{{ end }}
